package JAVATest;

import java.util.Random;

/**
 * ClassName:Text_019
 * Package:JAVATest
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/13-19:45
 * @Version:v1.0
 */
public class Text_019 {
    public static void main(String[] args) {
        //奖池
        int[] arr = {2, 588, 888, 1000, 10000};
        //新数组用于存储抽奖的结果
        int[] newArr = new int[arr.length];
        Random r = new Random();
        //抽奖
        for (int i = 0; i < 5; ) {
            //获取随机索引
            int randomIndex = r.nextInt(arr.length);
            int price = arr[randomIndex];
            //判断当前的奖项是否存在,如果存在则重新抽取,如果不存在,就表示是有效奖项
            boolean flag = contains(newArr, price);
            if (!flag) {
                //把当前抽取到的奖项添加到newArr当中
                newArr[i] = price;
                i++;
            }
        }
        for (int i = 0; i < newArr.length; i++) {
            System.out.println(newArr[i] + "元的奖金被抽出");
        }
    }

    public static boolean contains(int[] arr, int price) {
        //判断price在数组当中是否存在
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == price) {
                return true;
            }
        }
        return false;
    }
}
